package com.webull.information.center.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author chengang
 * @version 1.0
 * @date 16-5-17
 * @time 下午12:30
 * @since JDK 1.8
 */
public class CodeUtil {
	private static Properties ZH_DESC;

	/**
	 * 加载property文件
	 */
	static {
		try {
			ZH_DESC = getProperties(CodeUtil.class.getClassLoader().getResourceAsStream("webull-information-center/conf/return_code_zh_CN.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取property文件输入流
	 *
	 * @param inputStream
	 *            输入流
	 * @return Property对象
	 * @throws IOException
	 */
	private static Properties getProperties(InputStream inputStream) throws IOException {
		Properties prop = new Properties();
		prop.load(inputStream);
		return prop;
	}

	/**
	 * 根据code获取中文描述
	 *
	 * @param code
	 *            错误码
	 * @return 错误消息
	 */
	public static String getZH_Value(String code) {
		return ZH_DESC.getProperty(code);
	}
}
